package math;

/*
 *@description x 的平方根
 *@author hkfan
 *@version 1.0
 *@create 2025/6/18 16:04
 */
public class LeetCode_69 {

    public int mySqrt(int x) {
        if (x==0){
            return 0;
        }
        int l = 1,r = x,ans=-1;
        while (l<=r){
            int mid =  l + (r - l) / 2;
            if ((long)mid*mid>x){
                r=mid-1;
            } else{
                ans=mid;
                l=mid+1;
            }
        }
        return ans;
    }
}
